package com.wei.duowan.bbs;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.facebook.stetho.Stetho;
import com.tencent.bugly.crashreport.CrashReport;
import com.wei.duowan.bbs.constance.Constance;
import com.wei.duowan.bbs.sql.DaoMaster;
import com.wei.duowan.bbs.sql.DaoSession;
import com.wei.duowan.bbs.utils.Configuration;

/**
 * 作者：赵若位
 * 时间：2019/7/31 23:25
 * 联系方式：1070138445
 * 功能：
 */
public class App extends Application
{
    private static final String TAG = App.class.getSimpleName();


    private static Context sContext = null;
    private static Resources sResources = null;
    private static DaoSession mSession;

    @Override
    public void onCreate()
    {
        super.onCreate();
        sContext = getApplicationContext();
        sResources = sContext.getResources();
        CrashReport.initCrashReport(getApplicationContext(), Constance.BUGLY, false);
        Stetho.initializeWithDefaults(this);
        Log.e(TAG, "onCreate: " + Configuration.getInstance().getScreenWidth());
        Log.e(TAG, "onCreate: " + Configuration.getInstance().getScreenHeight());
        Log.e(TAG, "onCreate: " + Configuration.getInstance().getOpenglRender());
    }


    public static Context getContext()
    {
        return sContext;
    }


    public static Resources getResource()
    {
        return sResources;
    }


    public static DaoSession getSession()
    {
        if (mSession == null)
        {
//            String file = Configuration.getInstance().getPackName().concat("-db");
            String file = Configuration.getInstance().getPackName().concat(".db");
            DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(sContext, file);
            //如果采用getEncryptedWritableDb方式，则Stetho无法查看数据库文件
//            Database db = helper.getEncryptedWritableDb("yu548986");
            SQLiteDatabase db = helper.getWritableDatabase();
            mSession = new DaoMaster(db).newSession();
        }
        return mSession;
    }
}
